/**
 * <h2>字符流操作器相关.</h2>
 * <pre>
 * <b>请使用 {@link fybug.nulll.pdstream.Source.StreamSource.Strings} 生成操作源</b>
 * 操作器均有 <b>常规操作方法</b> 用于操作 <b>稳定流</b>
 * 在 <b>连续操作</b> 中可以使用接口对读取的片段进行处理
 * </pre>
 *
 * @author fybug
 * @version 0.0.8
 * @since JDK 1.8
 */
package fybug.nulll.pdstream.WR.Stream;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;

import java.nio.CharBuffer;

import fybug.nulll.pdstream.Interface.UpdateSize;
/** <h2>缓冲区操作.</h2> */
final
class Buffer {
    /** <p>更新字符缓冲区大小.</p> */
    @NotNull
    static
    CharBuffer upBufferSize(@Nullable final UpdateSize see, @NotNull CharBuffer charBuffer,
            final int readSize)
    {
        if (see != null) {
            synchronized ( charBuffer ){
                // 更新缓冲区大小
                int up = see.updataSize(readSize);
                if (up == charBuffer.capacity())
                    /* 缓冲区大小不变 */
                    charBuffer.clear();
                else {
                    if (up <= 0)
                        up = 0;
                    charBuffer = CharBuffer.allocate(up);
                }
            }
        }
        return charBuffer;
    }
}